import scrapy


class TongchengSpider(scrapy.Spider):
    name = "tongcheng"
    allowed_domains = ["dg.58.com"]
    start_urls = ["http://dg.58.com/"]

    def parse(self, response):
        # 返回网页源码
        # print(response.text)

        # 返回二进制数据
        # print(response.body)

        # 直接使用xpath
        text = response.xpath('//div[@class="article"]//h2/a')
        print(text)
        # 提起selector列表的第一个数据
        print(text.extract_first())
        # extract()提取selector对象的data属性值
        print(text.extract())